<template>
  <section class="component warehousing-application-button">
    <el-button
      @click="onClickButton"
      class="list-button white-button"
      size="mini"
      type="text"
      v-if="menuChannel !== 44 && menuChannel !== 34"
      >入库申请</el-button
    >
    <el-dialog
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :show-close="false"
      title="入库申请"
      :visible.sync="dialog"
      append-to-body
      width="650px"
      @open="$nextTick(() => $refs['warehousing-apply'].getGarageList())"
    >
      <warehousing-apply
        ref="warehousing-apply"
        :applyType="applyType.value"
        :caseIds="[caseId]"
        :fromChannel="fromChannel"
        :carFrameNo="carFrameNo"
        @close="dialog = false"
      ></warehousing-apply>
    </el-dialog>
  </section>
</template>
<script lang="ts">
import { Vue, Component, Prop } from "vue-property-decorator";
import WarehousingApply from "~/components/apply-component/warehousing-apply.vue";
import { State, namespace } from "vuex-class";
import {
  ApplyType,
  CASE_HALT_CATEGORY,
  MENU_CHANNEL
} from "~/config/enum.config";
import { CarManageService } from "~/services/domain-service/car-manage.service";
import { Dependencies } from "~/core/decorator";

const CollectionExecutionModule = namespace("collection-execution");

@Component({
  components: {
    WarehousingApply
  }
})
export default class WarehousingApplicationButton extends Vue {
  @Dependencies(CarManageService) private carManageService: CarManageService;
  @CollectionExecutionModule.State private caseId;
  @CollectionExecutionModule.State private menuChannel;
  @Prop() private carFrameNo;

  private dialog: boolean = false;
  private applyType: any = {};

  private get fromChannel() {
    const telChannel = [MENU_CHANNEL.Tel_team, MENU_CHANNEL.Tel_personal];
    const visitChannel = [MENU_CHANNEL.Visit_personal, MENU_CHANNEL.Visit_team];
    const legalChannel = [MENU_CHANNEL.Legal_personal, MENU_CHANNEL.Legal_team];

    if (telChannel.includes(this.menuChannel)) return "TEL";
    else if (visitChannel.includes(this.menuChannel)) return "VISIT";
    else if (legalChannel.includes(this.menuChannel)) return "LEGAL";
    else return "";
  }

  private onClickButton() {
    this.carManageService
      .getWarehouseCarByCaseInfoRecordId(this.caseId)
      .subscribe(data => {
        if (!data || (data && data === "IN_WAREHOUSE_REJECT"))
          this.dialog = true;
        else
          this.$message.error("该案件的车辆状态不符合条件，无法做入库申请！");
      });
  }
}
</script>
<style lang="less" scope></style>
